/*
 * Copyright 2010 Assert Developments
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.ad.coffeebreak.domain;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author Stefan Bangels
 */
@Entity
@Table(name = "PROJECT_HOURS", uniqueConstraints = {
        @UniqueConstraint(name = "PROJECT_HOURS_PROJECT_ID_AND_DATE_IDX", columnNames = {"projectId", "date"})}
)
@SequenceGenerator(name = "PROJECT_HOURS_SEQ", sequenceName = "PROJECT_HOURS_SEQ")
@NamedQueries(value = {
        @NamedQuery(name = ProjectHours.QUERY_FIND_PROJECT_HOURS,
                query = "SELECT ph FROM ProjectHours ph " +
                        "WHERE ph.projectId = :" + ProjectHours.QUERY_PARAM_PROJECT_ID + " " +
                        "AND ph.date = :" + ProjectHours.QUERY_PARAM_DATE)
})
@XmlRootElement
public class ProjectHours implements Serializable {

    // Queries
    public static final String QUERY_FIND_PROJECT_HOURS = "ProjectHours#findProjectHours";

    // Query parameters
    public static final String QUERY_PARAM_PROJECT_ID = "projectId";
    public static final String QUERY_PARAM_DATE = "date";

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PROJECT_HOURS_SEQ")
    private Long id;
    @NotNull
    private Long projectId;
    @NotNull
    private Date date;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name="projectHoursId", nullable = false)
    private Set<ExpectedProjectHours> expectedProjectHours;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name="projectHoursId", nullable = false)
    private Set<ActualProjectHours> actualProjectHours;
    private String comments;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Set<ExpectedProjectHours> getExpectedProjectHours() {
        return expectedProjectHours;
    }

    public void setExpectedProjectHours(Set<ExpectedProjectHours> expectedProjectHours) {
        this.expectedProjectHours = expectedProjectHours;
    }

    public Set<ActualProjectHours> getActualProjectHours() {
        return actualProjectHours;
    }

    public void setActualProjectHours(Set<ActualProjectHours> actualProjectHours) {
        this.actualProjectHours = actualProjectHours;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @Override
    public String toString() {
        return "ProjectHours{" +
                "id=" + id +
                ", projectId=" + projectId +
                ", date=" + date +
                ", expectedProjectHours=" + expectedProjectHours +
                ", actualProjectHours=" + actualProjectHours +
                ", comments='" + comments + '\'' +
                '}';
    }

}
